package com.yxj.aop;

import org.apache.tomcat.util.http.fileupload.RequestContext;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.condition.RequestConditionHolder;

import java.util.Date;

@Component
@Aspect
public class ExecTimeAdvice {

    private Logger logger = LoggerFactory.getLogger(ExecTimeAdvice.class);

    //定义切面
    @Pointcut("@annotation(com.yxj.annoation.ExecTimeAnn)")
    public void myPoint() {
    }

    @Around("myPoint()")
    public Object execTime(ProceedingJoinPoint pjp) throws Throwable {
        Long start = new Date().getTime();
        logger.info("总耗时："+start);
        //执行目标方法
        Object proceed = pjp.proceed();
        Long end = new Date().getTime();

        logger.info("总耗时："+(end-start));
        return proceed;
    }
}
